﻿@{
    ViewBag.Title = "会员注册";
    Layout = "~/Views/Shared/Main.cshtml";
    TempData["sidecalss"] = "EveryDayWisdom";

    var SearchParma = ViewData["SearchParma"] as HanGu.Entity.UniversallySearchParam ?? new HanGu.Entity.UniversallySearchParam();

}
@section Header
{
    <style>
        .contentLeft
        {
            width: 100%;
        }
        #partContent
        {
            width: 100%;
        }
        .movieContain
        {
            width: 100%;
            margin-top: 5px;
        }
    </style>
}
@section Banner
{
    @Html.Partial("Banner")
}
@section Content{
    <div class="contentLeft">
        <table cellpadding="0" cellspacing="0" id="partContent">
            <tr>
                <td>
                    <div class="ContentTitle">
                        <div class="ContentTitleLeft">
                            <img src="/Content/images/vipRegisterTitle.gif" width="145" height="26" alt=""></div>
                        <div class="ContentTitleRight">
                        </div>
                    </div>
                </td>
            </tr>
            <tr>
                <td class="content">
                    <div class="loginForm">
                        <form action="/vip/register" id="registerForm">
                        <p>
                            <label>
                                &nbsp;&nbsp;&nbsp;</label>
                            <input type="radio" name="registerType" value="1" checked onclick="SelectregisterType(this)" />邮箱&nbsp;&nbsp;&nbsp;
                            <input type="radio" name="registerType" value="2" onclick="SelectregisterType(this)" />手机
                        </p>
                        <p>
                            <label>
                                &nbsp;&nbsp;&nbsp;用户名：</label>
                            <input type="text" name="User" id="User" class="login_input required" style="width: 150px" />
                        </p>
                        <p>
                            <label>
                                &nbsp;&nbsp;&nbsp;密&nbsp;&nbsp;&nbsp;码：</label>
                            <input type="password" name="password" id="password" class="login_input required"
                                maxlength="30" minlength="6" style="width: 150px" />
                        </p>
                        <p>
                            <label>
                                确认密码：</label>
                            <input type="password" name="password2" id="password2" class="login_input required"
                                equalto="#password" style="width: 150px" />
                        </p>
                        <p id="selectEmail" style=" display:none;">
                            <label>
                                &nbsp;&nbsp;&nbsp;邮&nbsp;&nbsp;&nbsp;箱：</label>
                            <input type="text" name="email" id="email" class="login_input required email" style="width: 150px" />
                        </p>
                        <p id="selectTel">
                            <label>
                                &nbsp;&nbsp;&nbsp;手&nbsp;&nbsp;&nbsp;机：</label>
                            <input type="text" name="Tel" id="Tel" class="login_input required" style="width: 150px" />
                        </p>
                        <p id="selectCode">
                            <label>
                                &nbsp;&nbsp;&nbsp;校验码：</label>
                            <input name="code" id="code" class="login_input required code" type="text" size="5" />
                            <span><a href="#" onclick="getValidateCode()">点击获取校验码</a> </span>
                        </p>
                        <div class="login_bar">
                            <div style="width: 60px; float: left">
                                <input class="sub" type="submit" value="注册" style="width: 50px" /></div>
                        </div>
                        </form>
                    </div>
                </td>
            </tr>
        </table>
    </div>
}
@section Side{
    @Html.Partial("Side")
}
<script>
    function SelectregisterType(obj) {
        $this = $(obj);
        var selectEmail = $("#selectEmail");
        var selectTel = $("#selectTel");
        var selectCode = $("#selectCode");
        var registerType = $this.val();
        if (registerType == 1) {//邮箱
            selectEmail.hide();
            selectTel.show();
            selectCode.show();
        }
        else if (registerType = 2) {//手机
            selectEmail.show();
            selectTel.hide();
            //selectCode.hide();
         }
        else {
            alert("请选择手机或邮箱注册方式");
        }

    }
    function getValidateCode() {
        var email = $("#User").val();
        var registerType = $this.val();

        var emailt = /^\w+([-\.]\w+)*@@\w+([\.-]\w+)*\.\w{2,4}$/;
        var mobile = /^(((13[0-9]{1})|(15[0-9]{1}))+\d{8})$/;
        if (registerType == 1) {
            if (!emailt.test(email))
            { alert("请输入正确的邮箱！"); return false; }
            if (email == "") { alert("Email不能为空！"); return false; }
        }
        else {
            if (!mobile.test(email))
            { alert("请输入正确的手机！"); return false; }
            if (email == "") { alert("手机不能为空！"); return false; }
        }
        $.ajax({
            type: "POST",
            url: "/vip/getValidateCode/",
            data: "reciver=" + email + "&type=" + registerType,
            success: function (data) {
                var json = eval("(" + data + ")");
                if (json.statusCode == 200) {
                    alert("获取成功！")
                }
                else {
                    alert(json.message);
                }
            }
        });

    }
    $(function () {
        $("#registerForm").validate(
    { submitHandler: function (_this) {
        $this = $(_this);
        var user = $("#User", $this).val();
        var password = $("#password", $this).val();
        var password2 = $("#password", $this).val();
        var email = $("#email", $this).val();
        var code = $("#code", $this).val();
        var tel = $("#Tel").val();

        var registerType = $("input[name='registerType']:checked").val();
        var mobile = /^(((13[0-9]{1})|(15[0-9]{1}))+\d{8})$/;
        if (registerType == 1) {
            email = user;
            var emailrex = /^\w+([-\.]\w+)*@@\w+([\.-]\w+)*\.\w{2,4}$/;
            if (!emailrex.test(user))
            { alert("请输入正确的邮箱！"); return false; }
            var length = tel.length;
            if (length != 11 || !mobile.test(tel))
            { alert("请输入正确的手机号码"); return false; }

        } else if (registerType == 2) {
            var length = user.length;
            tel = user;
            if (length != 11 || !mobile.test(user))
            { alert("请输入正确的手机号码"); return false; }
        } else
        { alert("请选择注册方式手机或邮箱"); }

        $.ajax({
            type: "POST",
            url: "/vip/register",
            data: "UserName=" +escape(user) + "&Pwd=" + escape(password) + "&Email=" + escape(email) + "&code=" + code+"&Tel="+escape(tel) + "&registerType=" + registerType,
            success: function (data) {
                var json = eval("(" + data + ")");
                if (json.statusCode == 200) {
                    alert("注册成功，请重新登录");
                    top.location.href = json.forwardUrl;
                }
                else {
                    alert(json.message);
                }
            }
        });
    }
    }
);
    });
</script>
